<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">
<head>
    <meta charset="UTF-8">
    <script src="http://code.jquery.com/jquery-latest.js"></script>
    <title>操作页面</title>
</head>
<body>
    <form action="" method="get" id="form">
        <input type="hidden" th:value="${student==null}? '':${student.id}" name="id">
        <table>
            <tr>
                <td>姓名:</td>
                <td><input type="text" name="name" th:value="${student==null}? '':${student.name}"></td>
            </tr>
            <tr>
                <td>性别:</td>
                <td>
                    <input type="radio" name="sex" value="男" th:checked="${student!=null}?${student.sex=='男'?true:false}">男
                    <input type="radio" name="sex" value="女" th:checked="${student!=null}?${student.sex=='女'?true:false}">女
                </td>
            </tr>
            <tr>
                <td>年级:</td>
                <td>
                    <select name="gradeId">
                        <option th:each="grade:${grades}" th:value="${grade.gradeId}" th:selected="${student!=null}?${student.grade.gradeName==grade.gradeName}"  th:text="${grade.gradeName}"></option>
                    </select>
                </td>
            </tr>
            <tr>
                <td colspan="2"><input type="submit" value="提交"></td>
            </tr>
        </table>
    </form>

    <script type="text/javascript">
        $(function () {
            var id = $("input[name=id]").val();
            if (id==null || id==""){
                $("#form").attr("action","/add");
            }else{
                $("#form").attr("action","/modify");
            }
        })
    </script>
</body>
</html>